package com.rizzo.web.security;

/**
 * A POJO representing the relation between an URL and its roles.
 * The roles member is a String of an enumeration of roles.
 * This POJO is used as an intermediate between Acegi's ObjectDefenition
 * and the roles.xml file.
 *
 * @author jalieven
 */
public class RoleUrl {

    /** Field url  */
    private String url;

    /** Field roles  */
    private String roles;

    /**
     * Constructor RoleUrl creates a new RoleUrl instance.
     *
     * @param url of type String
     * @param roles of type String
     */
    public RoleUrl(String url, String roles) {
        this.url = url;
        this.roles = roles;
    }

    /**
     * Getter for property 'url'.
     *
     * @return Value for property 'url'.
     */
    public String getUrl() {
        return url;
    }

    /**
     * Setter for property 'url'.
     *
     * @param url Value to set for property 'url'.
     */
    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * Getter for property 'roles'.
     *
     * @return Value for property 'roles'.
     */
    public String getRoles() {
        return roles;
    }

    /**
     * Setter for property 'roles'.
     *
     * @param roles Value to set for property 'roles'.
     */
    public void setRoles(String roles) {
        this.roles = roles;
    }

    /**
     * TODO Method addRole ...
     *
     * @param role of type String
     */
    public void addRole(String role) {
        StringBuffer rolesStringBuffer = new StringBuffer(this.roles);
        rolesStringBuffer.append(",").append(role);
        this.roles = rolesStringBuffer.toString();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        result = PRIME * result + ((url == null) ? 0 : url.hashCode());
        return result;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object object) {
        if (!(object instanceof RoleUrl)) {
            return false;
        }
        RoleUrl roleUrl = (RoleUrl) object;
        return roleUrl.getUrl().equals(this.getUrl());
    }

    /**
     * {@inheritDoc}
     */
    public String toString() {
        return this.url + "=" + this.roles;
    }
}
